package service;

import dao.impl.AccountDao;
import dao.impl.AccountDaoImpl;
import dao.impl.UserDao;
import dao.impl.UserDaoImpl;
import javabean.Account;
import javabean.User;

import java.util.List;

public class UserServiceImpl implements UserService {
    //要有Dao对象
    private UserDao userDao = new UserDaoImpl();
    @Override
    public void registUser(User user) {
        userDao.saveUser(user);
    }

    @Override
    public User login(User user) {
        return userDao.queryUserByAccountAndPassword(user.getAccount(), user.getPassword());
    }

    @Override
    public boolean existsAccount(String account) {

        if (userDao.queryUserByaccount(account) == null) {
            // 等于null,说明没查到，没查到表示可用
            return false;
        }

        return true;
    }

    @Override
    public List<User> queryUserListByRole(Integer role) {
        return userDao.queryUserListByRole(role);
    }

    @Override
    public User queryUserById(Integer id) {
        return userDao.queryUserById(id);
    }

    @Override
    public int deleteUserById(Integer id) {
        return userDao.deleteUserById(id);
    }
}
